package com.atguigu.gmall.realtime.app.marketing.func;


import com.alibaba.fastjson.JSONObject;
import com.atguigu.gmall.realtime.app.marketing.bean.GmallEvent;
import com.atguigu.gmall.realtime.app.marketing.constant.MarketingConst;
import org.apache.flink.api.common.functions.FilterFunction;

// 过滤掉无uid的事件
public class BaseFilter implements FilterFunction<GmallEvent> {
    @Override
    public boolean filter(GmallEvent gmallEvent) throws Exception {
        if(gmallEvent.getTopic().equals(MarketingConst.TOPIC_PAGE)
        ||gmallEvent.getTopic().equals(MarketingConst.TOPIC_START)
        ||gmallEvent.getTopic().equals(MarketingConst.TOPIC_ACTION)
        ){
            JSONObject eventData = gmallEvent.getData();
            String uid = eventData.getJSONObject("common").getString("uid");
            if(uid==null){
                return  false;
            }
            return true;


        }


        return true;
    }
}
